package hu.rsc.forbiddenwords.client.gui.entry;

import hu.rsc.forbiddenwords.client.ForbiddenWordsServiceAsync;
import hu.rsc.forbiddenwords.client.Forbiddenwords;
import hu.rsc.forbiddenwords.client.table.AbstractFilterSupportTableModel;
import hu.rsc.forbiddenwords.shared.EntryDTO;

import com.google.gwt.gen2.table.client.TableModelHelper.Request;
import com.google.gwt.gen2.table.client.TableModelHelper.Response;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * @author Gyuri
 * 
 */
public class EntryTableModel extends AbstractFilterSupportTableModel<EntryDTO> {
    /**
     * The RPC service used to generate data, if RPC mode is enabled.
     */
    private ForbiddenWordsServiceAsync service = Forbiddenwords.getService();

    public EntryTableModel() {
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * com.google.gwt.gen2.table.client.TableModel#requestRows(com.google.gwt
     * .gen2.table.client.TableModelHelper.Request,
     * com.google.gwt.gen2.table.client.TableModel.Callback)
     */
    @Override
    public void requestRows(final Request request, final com.google.gwt.gen2.table.client.TableModel.Callback<EntryDTO> callback) {
	// Send RPC request for data
	this.service.getEntries(Forbiddenwords.getSelectedApplication().getId(), request, getColumnFilters(), new AsyncCallback<Response<EntryDTO>>() {

	    @Override
	    public void onFailure(Throwable caught) {
		// TODO Auto-generated method stub
	    }

	    @Override
	    public void onSuccess(Response<EntryDTO> result) {
		callback.onRowsReady(request, result);
	    }
	});
    }

    @Override
    protected boolean onRowInserted(int beforeRow) {
	return true;
    }

    @Override
    protected boolean onRowRemoved(int row) {
	return true;
    }

    @Override
    protected boolean onSetRowValue(int row, EntryDTO rowValue) {
	return true;
    }
}
